package com.sinopec.basemodule.dialog;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sinopec.basemodule.R;

public class TankerProgressDialog extends ProgressDialog {

    private TextView tvLoadText;
    private ImageView ivLoading;
    private int ImageRes = R.drawable.loading;
    private String msg = "正在加载中~";

    public TankerProgressDialog(Context context) {
        super(context);
//        init(getContext());
    }

    public TankerProgressDialog(Context context, int theme) {
        super(context, theme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init(getContext());
    }

    private void init(Context context) {
        //设置不可取消，点击其他区域不能取消，实际中可以抽出去封装供外包设置
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        setContentView(R.layout.load_dialog);
        tvLoadText = findViewById(R.id.tv_load_dialog);
        ivLoading = findViewById(R.id.iv_loading);

        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(params);
    }

    @Override
    public void show() {
        super.show();
        tvLoadText.setText(msg);
        Glide.with(getContext()).asGif().load(R.drawable.loading).into(ivLoading);
    }

    public void setText(String msg) {
        this.msg = msg;
    }

    public void setImage(int ImageRes) {
        this.ImageRes = ImageRes;
    }
}
